<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Dynamic Table</title>


    <link href="/public/js/iCheck/skins/minimal/blue.css" rel="stylesheet">

    <!--dynamic table-->
    <link href="/public/js/advanced-datatable/css/demo_page.css" rel="stylesheet" />
    <link href="/public/js/advanced-datatable/css/demo_table.css" rel="stylesheet" />
    <link rel="stylesheet" href="/public/js/data-tables/DT_bootstrap.css" />
    <?php $this->load->view('library/header');?>
    <style type="text/css">
        .out-supp-list li {
            padding-bottom: 20px;
            color: #65CEA7;
        }
        .zu-out p {
            font-size: 11px; color: #ff3044; margin: 0;
        }
    </style>
</head>
<body class="sticky-header">

<section>

    <?php $this->load->view('library/left');?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top');?>

        <!--body wrapper start-->
        <div class="wrapper">
            <div class="row">
                <div class="col-sm-12">
                    <?php $this->load->view('library/search');?>
                    <div class="out-sct">

                    </div>
                    <section class="panel">
                        <div class="panel-body">
                            <div class="adv-table">
                                <table class="display table table-bordered table-striped" id="dynamic-table">
                                    <thead>
                                    <tr>
                                        <th width="3%">编号</th>
                                        <th width="6%">图片</th>
                                        <th width="10%" class="center hidden-phone">货号</th>
                                        <th width="15%" class="hidden-phone">供货商</th>
                                        <th width="8%" class="hidden-phone">添加时间</th>
                                        <th width="5%" class="hidden-phone">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach ($goods_list as $item): ?>
                                        <tr class="gradeX">
                                            <td><label><input onclick="add_cookie(this)" class="goods_ids" <?php echo $item['export_goods'] ? 'checked' : '';?> name="goods_ids[]" type="checkbox" value="<?php echo $item['goods_id'];?>" /><?php echo $item['goods_id'];?></label></td>
                                            <td><img style="width: 100px;" src="<?php echo $item['original_img'];?>" /></td>
                                            <td class="up-jia">
                                                <?php echo $item['goods_sn'];?> 
                                                <?php if($item['is_on_sale'] == 1){?>
                                                    <a tabindex="0" role="button" style="margin-left: 5px;" class="badge badge-info">上架</a>
                                                    <?php }elseif($item['is_on_sale'] == 2){?>
                                                    <a tabindex="0" role="button" style="margin-left: 5px;" class="badge badge-important">部分下架</a>
                                                    <?php }else{?>
                                                    <a tabindex="0" role="button" style="margin-left: 5px;" class="badge badge-important">下架</a>
                                                <?php }?><br>
                                                <div class="on_salse" style="display: none;">
                                                    <h6>SKU</h6>
                                                    <div class="salse_sku">
                                                    <?php foreach($item['sku'] as $v){?>
                                                        <span class="btn btn-default btn-xs" <?php if($v['is_on_sale'] != 1){
                                                            echo "style='color:red'";}?>><?php echo $v['size'].'/';echo $v['color']; echo $v['is_on_sale'] == 1 ?  '上架': '下架';?></span>
                                                    <?php }?>
                                                    </div>
                                                    <h6>站点</h6>
                                                    <div class="salse_web">
                                                    <?php foreach($item['web'] as $v){?>
                                                        <span class="btn btn-default btn-xs" <?php if($v['is_sales'] != 1){
                                                            echo "style='color:red'";}?>><?php echo $v['web_name']; echo $v['is_sales'] == 1 ?  '上架': '下架';?></span>
                                                    <?php }?>
                                                    </div>
                                                </div>
                                                
                                            </td>
                                            <td class="hidden-phone">
                                                <a target="_blank" href="<?php echo $item['supp_url'];?>"><?php echo $item['suppliers_name'];?></a>
                                            </td>
                                            <td class="center hidden-phone"><?php echo date('Y-m-d', $item['add_time']);?></td>
                                            <td class="hidden-phone">
<a class="btn btn-xs btn-info off_shelve" href="#myModal" data-is="1" data-id="<?php echo $item['goods_id']; ?>" data-toggle="modal"  >下架</a>
<!--<a class="btn btn-xs btn-info open_shelve" href="#myModal" data-is="2" data-id="--><?php //echo $item['goods_id']; ?><!--" data-toggle="modal"  >上架</a>-->
                                                
                                            </td>
                                        </tr>
                                    <?php endforeach;?>
                                    </tbody>
                                </table>
                            </div>
                            <div class="row-fluid">
                                <div class="span6">
                                    <div class="dataTables_paginate paging_bootstrap pagination">
                                        <ul>
                                            <?php echo $pages;?>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </div>

        <!--body wrapper end-->

        <!--footer section start-->
        <footer>
            2014 &copy; AdminEx by
        </footer>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">下架产品</h4>
            </div>
            <div class="modal-body">

                <form role="form" id="commentForm" >
                    <div class="form-group">
                        <label for="exampleInputEmail1" style="font-weight: 700">SKU信息</label>
                        <div class="modal-sku icheck">
                        </div>
                    </div>
                    <!--<div class="form-group">
                        <label for="exampleInputPassword1" style="font-weight: 700" >上架站点</label>
                        <div class="modal-web icheck">
                        </div>
                    </div>-->
                    <div class="form-group">
                        <label for="exampleInputPassword1" style="font-weight: 700;margin-right: 20px;" >下架原因</label>
                        <div class="reason" style="width: 50%; padding-top: 10px;">
                            <select class="form-control" name="reason">
                                <option value="0">请选择</option>
                                <option value="1">缺货</option>
                                <option value="2">断货</option>
                                <option value="3">质检不合格</option>
                                <option value="4">侵权</option>
                                <option value="5">滞销</option>
                                <option value="6">预售失败</option>
                            </select>
                        </div>
                    </div>
                    <input type="hidden" name="goods_id" value="" />
                    <button type="submit" class="btn btn-primary is_on_sale">确定</button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('library/footer');?>
<!--icheck -->
<script src="/public/js/iCheck/jquery.icheck.js"></script>
<script src="/public/js/icheck-init.js"></script>

<script type="text/javascript">
    $(function () {

        $('.badge').popover({
            'trigger':'focus',
            'html': true,
            'content': function () {
                return $(this).nextAll('.on_salse').html();
            }
        });

        $.get('<?php echo base_url('Product/outstock?'); ?>'+window.location.search.substring(1), function (data) {
            $('.out-sct').html(data);
        }, 'html');
    });


    $('.off_shelve').on('click', function () {
        var id = $(this).attr('data-id');
        var is = $(this).data('is');
        $('.is_on_sale').attr('is_on_sale',is);

        $('input[name="goods_id"]').val(id);
        $('.icheck').html('');

        $.get('<?php echo base_url('Product/off_shelve/goods_id/');?>'+id, function (data) {

            if (data.status == 'success') {

                var sku_list = data.data.sku_list;
                var sku_html = '';
                for (x in sku_list) {
                    sku_html += '<div class="minimal-blue single-row"><div class="checkbox "><input name="sku[]" value="'+sku_list[x].sku_id+'" type="checkbox" ' + (sku_list[x].is_on_sale == 1 ? 'checked' : '') + '><label title="' + sku_list[x].color + ' / ' + sku_list[x].size + '">' + sku_list[x].sku_sn + '</label></div></div>';
                }
                $('.modal-sku').html(sku_html+'<div class="clear"></div>');

                /*var web_list = data.data.web_list;
                var web_html = '';
                for (x in web_list) {
                    web_html += '<div class="minimal-blue single-row"><div class="checkbox "><input name="web[]" value="'+web_list[x].sg_id+'" type="checkbox" ' + (web_list[x].is_sales == 1 ? 'checked' : '') + '><label>' + web_list[x].web_name + '</label></div></div>';
                }
                $('.modal-web').html(web_html+'<div class="clear"></div>');*/

                $('.icheck input').iCheck({
                    checkboxClass: 'icheckbox_minimal-blue',
                    radioClass: 'iradio_minimal-blue',
                    increaseArea: '20%',
                    labelHover: true,
                });

            } else {

                swal({
                    title: data.info,
                    text: '2秒后关闭',
                    type: data.status,
                    allowOutsideClick: false,
                    timer: data.stop ? data.stop : 1500,
                    showConfirmButton: false
                }).then(function(isConfirm) {
                    location.reload();
                });
            }

        },'json');
    });
    $('#commentForm').submit(function () {
        var id = $(this).data('is');
        var is_on_sale = $('.is_on_sale').attr('is_on_sale');

        if(is_on_sale == 1){
            var url = '<?php echo base_url('Product/off_shelve/');?>';
        }else{
            var url = '<?php echo base_url('Product/open_shelve/');?>';
        }
        t = setTimeout(function() {
            $('#commentForm .btn-primary').attr('disabled','disabled').addClass('btn-submit-disabled').html('正在提交，请稍等...');
        }, 200);

        var data = new FormData(this);
        $.ajax({
            type: 'POST',
            url: url,
            data: data,
            success: function (data) {
                clearTimeout(t);
                    swal({
                        title: data.info,
                        text: '2秒后关闭',
                        type: data.status,
                        allowOutsideClick: false,
                        timer: data.stop ? data.stop : 1500,
                        showConfirmButton: false
                    }).then(function(isConfirm) {
                        location.reload();
                    });
            },
            dataType:'json',
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    });



    $('.open_shelve').on('click', function () {
        var id = $(this).attr('data-id');
        var is = $(this).data('is');
        $('.is_on_sale').attr('is_on_sale',is);

        $('input[name="goods_id"]').val(id);
        $('.icheck').html('');

        $.get('<?php echo base_url('Product/open_shelve/goods_id/');?>'+id, function (data) {

            if (data.status == 'success') {

                var sku_list = data.data.sku_list;
                var sku_html = '';
                for (x in sku_list) {
                    sku_html += '<div class="minimal-blue single-row"><div class="checkbox "><input name="sku[]" value="'+sku_list[x].sku_id+'" type="checkbox" ' + (sku_list[x].is_on_sale == 1 ? 'checked' : '') + '><label title="' + sku_list[x].color + ' / ' + sku_list[x].size + '">' + sku_list[x].sku_sn + '</label></div></div>';
                }

                var web_list = data.data.web_list;
                var web_html = '';
                for (x in web_list) {
                    web_html += '<div class="minimal-blue single-row"><div class="checkbox "><input name="web[]" value="'+web_list[x].sg_id+'" type="checkbox" ' + (web_list[x].is_sales == 1 ? 'checked' : '') + '><label>' + web_list[x].web_name + '</label></div></div>';
                }

                $('.modal-sku').html(sku_html+'<div class="clear"></div>');
                $('.modal-web').html(web_html+'<div class="clear"></div>');


                $('.icheck input').iCheck({
                    checkboxClass: 'icheckbox_minimal-blue',
                    radioClass: 'iradio_minimal-blue',
                    increaseArea: '20%',
                    labelHover: true,
                });

            } else {

                swal({
                    title: data.info,
                    text: '2秒后关闭',
                    type: data.status,
                    allowOutsideClick: false,
                    timer: data.stop ? data.stop : 1500,
                    showConfirmButton: false
                }).then(function(isConfirm) {
                    location.reload();
                });
            }


        },'json');
    });


</script>

<!--dynamic table-->
<!--<script type="text/javascript" language="javascript" src="/public/js/advanced-datatable/js/jquery.dataTables.js"></script>-->
<!--<script type="text/javascript" src="/public/js/data-tables/DT_bootstrap.js"></script>-->
<!--dynamic table initialization -->
<!--<script src="/public/js/dynamic_table_init.js"></script>-->

<!--common scripts for all pages-->
<script src="/public/js/scripts.js"></script>

</body>
</html>
